home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $ClipMagicTemplate < prev    next >
Encoding:
Text File  |  1995-01-23  |  1.3 KB  |  44 lines  |  [TEXT/KEEN]

  1. #$ClipMagicTemplate: you can use this as the basis for your
  2. # own clipboard changers. This example just truncates the
  3. # clip to its last line.
  4. BEGIN {
  5.     clipCharsToWatch = 32;
  6.     while (1) # run until <Command><period>...
  7.         {
  8.         # see if clipboard has changed
  9.         if ((newClip = getclip(clipCharsToWatch)) != oldClip)
  10.             {
  11.             oldClip = newClip;
  12.             # a leading space is used as the trigger
  13.             if (substr(newClip, 1,1) == " ")
  14.                 DoSomething()
  15.             }
  16.         }
  17.     }
  18.  
  19. function DoSomething(            fullClip, numLines, lines, outClip, out)
  20.     {
  21.     fullClip = getclip(); # gets calling editor's private clip
  22.     numLines = split(fullClip, lines, "\r");
  23.     # with "split", the last line will be empty if the last
  24.     # character copied was a return.
  25.     if (lines[numLines] == "")
  26.         --numLines;
  27.     
  28.     #...do things with the clipboard, and create the new clip "out"
  29.     ### just for example, keep only the last line of the old clip
  30.     out = out lines[numLines] "\r";
  31.     
  32.     # In this specific case, since we are looking for a space at
  33.     # the beginning of the clip, make sure our new clip does NOT
  34.     # start with a space
  35.     sub(/^[ ]+/, "", out); # that's a [space] there
  36.     
  37.     # send the result back to the calling editor's clip
  38.     putclip(out);
  39.     # update "oldClip"
  40.     oldClip = substr(out, 1, 32);
  41.     # flash menu bar to signal something happened
  42.     beep(0);
  43.     }
  44.